home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / TurboTCP 1.0.1 / Aliases / About box classes / CAboutDirector.cp < prev    next >
Encoding:
Text File  |  1993-12-10  |  4.8 KB  |  225 lines  |  [TEXT/KAHL]

  1. /*
  2. ** CAboutDirector.cp
  3. **
  4. **    About box library
  5. **    Dialog director class
  6. **
  7. **    Copyright © 1993, FrostByte Design / Eric Scouten
  8. **
  9. */
  10.  
  11.  
  12. #include "CAboutDirector.h"
  13.  
  14. #include <Commands.h>
  15. #include <TCLUtilities.h>
  16. #include <CApplication.h>
  17. #include <CDesktop.h>
  18. #include <CSwitchboard.h>
  19. #include <CList.h>
  20. #include <CDecorator.h>
  21. #include <CAbstractText.h>
  22. #include <CButton.h>
  23. #include <CDecorator.h>
  24.  
  25. #include "CAboutDialog.h"
  26.  
  27.  
  28. // TCL global variables
  29.  
  30. extern CApplication    *gApplication;
  31. extern CDecorator    *gDecorator;
  32. extern CDesktop    *gDesktop;
  33. extern long        gSleepTime;
  34.  
  35.  
  36. //    —— construction/destruction ——
  37.  
  38. /*______________________________________________________________________
  39. **
  40. ** IAboutDirector
  41. **
  42. **    Initialize the pane. Nothing special here.
  43. **
  44. **        DLOGid (short):                    the dialog’s resource ID
  45. **        aSupervisor (CDirectorOwner):        who owns us (usually the application)
  46. **
  47. */
  48.  
  49. void CAboutDirector::IAboutDirector (short DLOGid, CDirectorOwner *aSupervisor)
  50.  
  51. {
  52.     CAboutDialog    *theDialog;
  53.  
  54.     CDialogDirector::IDialogDirector(aSupervisor);
  55.     
  56.     hasButtons = FALSE;
  57.     expireTicks = 0;
  58.     itsWindow = theDialog = new (CAboutDialog);
  59.     theDialog->IAboutDialog(DLOGid, gDesktop, this);
  60.     gDecorator->CenterWindow(theDialog);
  61.  
  62. }
  63.  
  64.  
  65. //    —— displaying methods ——
  66.  
  67. /*______________________________________________________________________
  68. **
  69. ** DoAbout
  70. **
  71. **    Respond to the About… command. Default behavior is to display a modal dialog box, then
  72. **    disposes of the dialog & this director object when completed. If you override this method,
  73. **    ensure that the dialog & director are disposed when the dialog is completed.
  74. **
  75. **        killButtons (Boolean):    true to eliminate all push buttons from this dialog
  76. **                                 (useful as a splash screen)
  77. **        maxTicks (long):        maximum # ticks to display about box; if this is non-zero,
  78. **                                the box closes after maxTicks ticks (useful as a splash screen)
  79. **
  80. */
  81.  
  82.     static Boolean AboutDirector_KillButtons (CView *aView, void *targetID)
  83.     {
  84.         if (member (aView, CButton))
  85.             aView->Hide();
  86.         return FALSE;
  87.     }
  88.     
  89.     static Boolean AboutDirector_IsAButton (CView *aView, void *targetID)
  90.     {
  91.         return (member (aView, CButton));
  92.     }
  93.     
  94. void CAboutDirector::DoAbout (Boolean killButtons, short maxTicks)
  95.  
  96. {
  97.     CDialog        *itsDialog = (CDialog*) itsWindow;
  98.     tGopherInfo    gopherInfo;
  99.     Boolean        wasLocked;
  100.  
  101.  
  102.     // check to see if there are buttons
  103.     
  104.     hasButtons = FALSE;
  105.     if (killButtons)
  106.         itsDialog->MatchView(&AboutDirector_KillButtons, NULL);
  107.     else {
  108.         if (itsDialog->MatchView(&AboutDirector_IsAButton, NULL))
  109.             hasButtons = TRUE;
  110.     }
  111.  
  112.  
  113.     // set expiration time
  114.     
  115.     if (maxTicks)
  116.         expireTicks = Ticks + maxTicks;
  117.     else
  118.         expireTicks = 0;
  119.  
  120.  
  121.     // enter modal dialog loop
  122.     //    (don’t use DoModalDialog because we need custom behaviors)
  123.  
  124.     if (hasButtons) {
  125.         itsDialog->SetDefaultCmd(cmdOK);
  126.         itsDialog->SetModal(kModal);
  127.     }
  128.     itsDialog->Select();
  129.     if (hasButtons)
  130.         DisableTheMenus();
  131.     
  132.     
  133.     // set the initial gopher
  134.  
  135.     itsDialog->FindGophers(&gopherInfo);
  136.     itsGopher = gopherInfo.firstGopher? gopherInfo.firstGopher : itsDialog;
  137.     
  138.     if (member (itsGopher, CAbstractText))
  139.         ((CAbstractText *) itsGopher)->SelectAll(TRUE);
  140.         
  141.     if (active)
  142.         itsGopher->BecomeGopher( TRUE);
  143.  
  144.  
  145.     // run the dialog
  146.  
  147.     dismissCmd = cmdNull;
  148.     
  149.     TRY {
  150.         do {
  151.             if (hasButtons)
  152.                 gApplication->Process1Event();
  153.             else
  154.                 PseudoModalGetNextEvent();
  155.             if ((expireTicks) && (Ticks >= expireTicks))
  156.                 dismissCmd = cmdOK;
  157.         } while (dismissCmd == cmdNull);
  158.     }
  159.     CATCH {
  160.         if (gLastError != kSilentErr)
  161.             ErrorAlert(gLastError, gLastMessage);
  162.         RETRY;
  163.     }
  164.     ENDTRY;
  165.  
  166.  
  167.     // clean out the window so it doesn’t break up into several images
  168.  
  169.     if (itsDialog->itsSubviews) {
  170.         itsDialog->itsSubviews->DisposeAll();
  171.         itsDialog->itsSubviews = NULL;
  172.     }
  173.     itsDialog->Update();
  174.     
  175.     // we’re done…
  176.         
  177.     if (hasButtons)
  178.         EnableTheMenus();        
  179.     Dispose();
  180.  
  181. }
  182.  
  183.  
  184. /*______________________________________________________________________
  185. **
  186. ** PseudoModalGetNextEvent
  187. **
  188. **    Watch for events that would signal closing the about box or splash screen. This routine
  189. **    is a hybrid of CSwitchboard::Process1Event and CSwitchboard::GetNextEvent. Since it
  190. **    is used for splash screens (i.e. before app init is completed), it can’t respond in the normal
  191. **    fashion.
  192. **
  193. */
  194.  
  195. #define someEvents        mDownMask + keyDownMask + updateMask
  196.  
  197. void CAboutDirector::PseudoModalGetNextEvent (void)
  198.  
  199. {
  200.     EventRecord    macEvent;                // Mac Event to be processed
  201.     Boolean        isMyEvent;            // should program handle event?
  202.     Point            mouseLoc;                // mouse location in global coords
  203.  
  204.  
  205.     // grab a mouse-down, key-down, or update event ONLY
  206.  
  207.     if (gSystem.hasWNE) 
  208.         isMyEvent = WaitNextEvent(someEvents, &macEvent, gSleepTime, NULL);
  209.     else {
  210.         SystemTask();
  211.         isMyEvent = GetNextEvent(someEvents, &macEvent);
  212.     }
  213.     
  214.     
  215.     // respond ONLY to update events; mouse/key downs cancel the dialog & get discarded
  216.  
  217.     if (isMyEvent) {
  218.         if (macEvent.what == updateEvt)
  219.             gApplication->itsSwitchboard->DispatchEvent(&macEvent);
  220.         else
  221.             dismissCmd = cmdOK;
  222.     }
  223.  
  224. }
  225.